package com.example.weli.ble2test;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
import java.io.InputStream;

public class Battyview extends View {
    boolean blackc = false;
    float cruu_vol = 0.0f;
    String displays;
    Bitmap mBitmap_no;
    Bitmap mBitmap_to;
    private Paint mPaint_Text;
    InputStream not;
    Path path;
    Path path2;
    InputStream t;

    public Battyview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initial_bat();
    }

    public Battyview(Context context) {
        super(context);
        initial_bat();
    }

    public Battyview(Context context, AttributeSet attrs) {
        super(context, attrs);
        initial_bat();
    }

    void initial_bat() {
        this.mBitmap_no = BitmapFactory.decodeResource(getResources(), R.drawable.e_100);
        this.mBitmap_to = BitmapFactory.decodeResource(getResources(), R.drawable.f_full);
        this.mPaint_Text = new Paint();
        this.mPaint_Text.setColor(Color.rgb(51, 51, 51));
        this.mPaint_Text.setTextSize(14.0f);
        this.mPaint_Text.setFakeBoldText(true);
        this.path = new Path();
        this.path.moveTo(15.0f, 3.0f);
        this.path.lineTo(15.0f, 30.0f);
        this.path2 = new Path();
        this.path2.moveTo(15.0f, 8.0f);
        this.path2.lineTo(15.0f, 30.0f);
        this.displays = new String();
        this.displays = Float.toString(this.cruu_vol).toString();
    }

    public void set_vol(float vol) {
        this.cruu_vol = vol;
        this.displays = Float.toString(this.cruu_vol).toString();
        invalidate();
    }

    public void set_backcbmp(boolean isblue) {
        this.blackc = isblue;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Bitmap resizedBitmap;
        super.onDraw(canvas);
        Matrix matrix = new Matrix();
        matrix.setRotate(-90.0f);
        if (this.blackc) {
            resizedBitmap = Bitmap.createBitmap(this.mBitmap_no, 0, 0, 38, 38, matrix, true);
        } else {
            resizedBitmap = Bitmap.createBitmap(this.mBitmap_to, 0, 0, 38, 38, matrix, true);
        }
        canvas.drawBitmap(resizedBitmap, 0.0f, 0.0f, null);
        if (this.displays.length() <= 3) {
            canvas.drawTextOnPath(this.displays, this.path2, 0.0f, 0.0f, this.mPaint_Text);
            return;
        }
        canvas.drawTextOnPath(this.displays, this.path, 0.0f, 0.0f, this.mPaint_Text);
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(38, 38);
    }
}
